/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servetestbytebuffer;

import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
import java.util.Arrays;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author ThanhTri
 */
public class ServeTestByteBuffer {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        ServerSocketChannel ssc;
        try {
            ssc = ServerSocketChannel.open();
            ssc.socket().bind(new InetSocketAddress(InetAddress.getLocalHost(),5000));
//            ssc.configureBlocking(false);
            
            while(true){
                SocketChannel client = ssc.accept();
                ByteBuffer b = ByteBuffer.allocate(512);
                b.clear();
                client.read(b);
                b.flip();
                System.out.println("First :"+ b.getInt());
//                System.out.println("second: "+b.getInt());
//                byte dst[] = new byte[b.remaining()];
//                b.get(dst);
//                String s = new String(dst);
//                System.out.println("String :"+s);
            }
        } catch (IOException ex) {
            Logger.getLogger(ServeTestByteBuffer.class.getName()).log(Level.SEVERE, null, ex);
        }

    }
}
